/**
 * Application GUI.
 */

// Default window level presets.
dwv.tool.defaultpresets = {};
// Default window level presets for CT.
dwv.tool.defaultpresets.CT = {
    "mediastinum": { "center": 40, "width": 400 },
    "lung": { "center": -500, "width": 1500 },
    "bone": { "center": 500, "width": 2000 },
};

// decode query
dwv.utils.decodeQuery = dwv.utils.base.decodeQuery;

// Window
dwv.gui.getWindowSize = dwv.gui.base.getWindowSize;
// Progress
dwv.gui.displayProgress = function (/*percent*/) { /*does nothing*/ };
// get element
dwv.gui.getElement = dwv.gui.base.getElement;
// refresh
dwv.gui.refreshElement = dwv.gui.base.refreshElement;
// Slider
dwv.gui.Slider = null;
// Tags table
dwv.gui.DicomTags = null;
dwv.gui.Draw = dwv.gui.base.Draw;

// Loaders
dwv.gui.Loadbox = dwv.gui.base.Loadbox;
// File loader
dwv.gui.FileLoad = dwv.gui.base.FileLoad;

// Url loader
dwv.gui.UrlLoad = dwv.gui.base.UrlLoad;

// Toolbox
dwv.gui.Toolbox = function (app) {

    this.setup = function (list) {
        //tool bar--------------------------------------------------------------
        var buttonDraw = document.createElement("button");
        buttonDraw.className = "Draw-button";
        buttonDraw.value = "Draw";
        buttonDraw.onclick = app.onChangeTool;
        buttonDraw.appendChild(document.createTextNode(dwv.i18n("basics.draw")));

        var buttonUndo = document.createElement("button");
        buttonUndo.className = "Undo-button";
        buttonUndo.value = "Undo";
        buttonUndo.onclick = app.onUndo;
        buttonUndo.appendChild(document.createTextNode(dwv.i18n("basics.undo")));

        var buttonReset = document.createElement("button");
        buttonReset.className = "reset-button";
        buttonReset.value = "reset";
        buttonReset.onclick = app.onDisplayReset;
        buttonReset.appendChild(document.createTextNode(dwv.i18n("basics.reset")));

        var btnSaveState = document.createElement("button");
        btnSaveState.className = "saveState-button";
        btnSaveState.value = "saveState";

        var toggleSaveState = document.createElement("a");
        toggleSaveState.className = "saveState-button download-state";
        toggleSaveState.value = "saveState";
        toggleSaveState.onclick = app.onStateSave;
        toggleSaveState.download = "state.json";
        toggleSaveState.appendChild(document.createTextNode(dwv.i18n("basics.saveState")));

        var node = app.getElement("toolbar");
        node.appendChild(buttonUndo);
        node.appendChild(buttonReset);
        btnSaveState.appendChild(toggleSaveState);
        node.appendChild(btnSaveState);
        node.appendChild(buttonDraw);

        dwv.gui.refreshElement(node);
    };
    this.display = function (flag) {
    };
    this.initialise = function (list) {
        // not wonderful: first one should be scroll is more than one slice
        if (list[0] === false) {
            var inputScroll = app.getElement("scroll-button");
            inputScroll.style.display = "none";
            var inputZoom = app.getElement("zoom-button");
            inputZoom.checked = true;
        }
    };
};

// Window/level
dwv.gui.WindowLevel = function (app) {
    this.setup = function () {
        var button = document.createElement("button");
        button.className = "wl-button";
        button.value = "WindowLevel";
        button.onclick = app.onChangeTool;
        button.appendChild(document.createTextNode(dwv.i18n("tool.WindowLevel.name")));

        var node = app.getElement("toolbar");
        node.appendChild(button);
    };
    this.display = function (bool) {
        var button = app.getElement("wl-button");
        button.disabled = bool;
    };
    this.initialise = function () {
        // clear previous
        dwv.html.removeNode(app.getElement("presetSelect"));
        dwv.html.removeNode(app.getElement("presetLabel"));

        // create preset select
        var select = dwv.html.createHtmlSelect("presetSelect",
            app.getViewController().getWindowLevelPresetsNames(), "wl.presets", true);
        select.className = "presetSelect";
        select.onchange = app.onChangeWindowLevelPreset;
        select.title = "Select w/l preset.";
        select.setAttribute("data-inline", "true");
        var label = document.createElement("label");
        label.className = "presetLabel";
        label.setAttribute("for", "presetSelect");
        label.appendChild(document.createTextNode(dwv.i18n("basics.presets") + ": "));

        var node = app.getElement("toolbar");
        node.appendChild(label);
        node.appendChild(select);
    };
};

// Zoom
dwv.gui.ZoomAndPan = function (app) {
    this.setup = function () {
        var button = document.createElement("button");
        button.className = "zoom-button";
        button.value = "ZoomAndPan";
        button.onclick = app.onChangeTool;
        button.appendChild(document.createTextNode(dwv.i18n("tool.ZoomAndPan.name")));

        var node = app.getElement("toolbar");
        node.appendChild(button);
    };
    this.display = function (bool) {
        var button = app.getElement("zoom-button");
        button.disabled = bool;
    };
};

// Scroll
dwv.gui.Scroll = function (app) {
    this.setup = function () {
        var button = document.createElement("button");
        button.className = "scroll-button";
        button.value = "Scroll";
        button.onclick = app.onChangeTool;
        button.appendChild(document.createTextNode(dwv.i18n("tool.Scroll.name")));

        var node = app.getElement("toolbar");
        node.appendChild(button);
    };
    this.display = function (bool) {
        var button = app.getElement("scroll-button");
        button.disabled = bool;
    };
};

//Reset
dwv.gui.appendResetHtml = function (app) {

};
// ColourTool
dwv.gui.ColourTool = dwv.gui.base.ColourTool;
// Undo/redo
dwv.gui.Undo = dwv.gui.base.Undo;